package video

import (
	"fmt"
	"gitee.com/mootok/mootok/src/constant/config"
	"math/rand"
	"strings"
	"time"
)

var uploadVideoLimitKeyPrefix = config.EnvConfig.RedisPrefix + "upload_freq_limit"

func genRandomString(length int) string {
	r := rand.New(rand.NewSource(time.Now().UnixNano()))

	b := make([]byte, length)
	for i := range b {
		b[i] = letterBytes[r.Intn(len(letterBytes))]
	}
	return string(b)
}

func genFilename(prefix string, userID int, suffix string) string {
	timestamp := time.Now().Unix()
	randomString := genRandomString(5)
	return fmt.Sprintf("%s/%d/%d-%s%s", prefix, userID, timestamp, randomString, suffix)
}

func genUploadLimiterKey(userID int) string {
	return fmt.Sprintf("%s-%d", uploadVideoLimitKeyPrefix, userID)
}

func extractKeywords(description string) []string {
	var keywords []string

	// Split the description into words
	words := strings.Fields(description)

	// Iterate over the words and check for keywords starting with a hashtag
	for _, word := range words {
		if strings.HasPrefix(word, "#") {
			// Remove the hashtag from the keyword
			keyword := strings.TrimPrefix(word, "#")
			keywords = append(keywords, keyword)
		}
	}

	return keywords
}
